import java.net.*;
import java.io.*;

public class Server3
{
	public static void main(String [] args) throws IOException 
	{
		//1. Mo 1 socket va cho ket noi to client
		ServerSocket serverSocket = null;
		String data = "Hello, Client";
		BufferedReader in = null;
		try{
			serverSocket = new ServerSocket(4560);
			System.out.println("Server listening on port 4560");
		}catch(IOException e){
			System.err.println(e);
			System.exit(1);
		}
		Socket clientSocket = null;
		PrintWriter out = null;
		try{
			clientSocket = serverSocket.accept();
			//Send
			out = new PrintWriter(clientSocket.getOutputStream(), true);
			out.print(data);
			
			//Receive
			in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			String data2 = in.readLine();
			System.out.println(data2);
			in.close();
			out.close();
		}catch(IOException e){
			System.out.println("Access denied!");
			System.exit(1);
		}
		//2. dong socket
		clientSocket.close();
		serverSocket.close();
	}
}